(function($){
    function initSetState() {
        $('.but_set_state').on('click', function(){
            var obj = $(this);
            var state = obj.attr('dstate');
            var id = obj.attr('did');
            var url = obj.attr('durl');
            var info = '删除';
            switch(state) {
                case '-1':
                    info = '删除';
                    break;
                case '0':
                    info = '恢复';
                    break;
                case '1':
                    info = '发布';
                    break;
            }
            layer.confirm(
                '确定要【' + info + '】此提问吗？',
                {
                    icon: 3,
                    title: '系统提示',
                    btn: ['确 定', '取 消']
                },
                function(index){
                    layer.close(index);
                    layer.load();
                    $.post(
                        url,
                        {id: id, state: state},
                        function(data){
                            if(data.status == 10000) {
                                location.reload(true);
                            } else {
                                layer.closeAll();
                                layer.alert(data.errmsg);
                            }
                        },
                        'json'
                    );
                },
                function(index){
                    layer.close(index);
                }
            );
        });
    }
    function openPage() {
        var obj = $(this);
        var url = obj.attr('durl');
        var title = '回答列表';
        layer.open({
            type: 2,
            title: title,
            shadeClose: false,
            shade: 0.8,
            maxmin: true, //开启最大化最小化按钮
            area: ['100%', '90%'],
            content: url
        });
    }

    /*数据修改保存*/
    $('.edit_edit .edit').click(function(){
        if($(this).parents('tr').hasClass('on')){
            $(this).next().click();
        }else{
            $(this).parents('tr').addClass('on');
            $(this).parents('tr').find("select").removeAttr("disabled");
            $(this).text('保存');
        }
    })
    $(function(){
        $('#activity_time').daterangepicker({
            "autoUpdateInput": false,
            "showDropdowns": true,
            "timePicker": true,
            "timePicker24Hour": true,
            "timePickerIncrement": 1,
            "autoApply": true,
            "locale": {
                "format": "YYYY-MM-DD HH:mm",
                "separator": " 至 ",
                "applyLabel": "确 定",
                "cancelLabel": "取 消",
                "fromLabel": "From",
                "toLabel": "To",
                "daysOfWeek": ["日", "一", "二", "三", "四", "五", "六"],
                "monthNames": ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
                "firstDay": 1
            },
            "opens": "right",
            "drops": "down",
            "buttonClasses": "btn btn-sm",
            "applyClass": "btn-success",
            "cancelClass": "btn-default"
        }, function(start, end, label) {

        });
        $('#activity_time').on('apply.daterangepicker', function(ev, picker) {
            $(this).val(picker.startDate.format('YYYY-MM-DD HH:mm') + ' 至 ' + picker.endDate.format('YYYY-MM-DD HH:mm'));
        });
        $('#activity_time').on('cancel.daterangepicker', function(ev, picker) {
            $(this).val('');
        });
    	
    	
    	
        initSetState();
        $('.but_answer_list').on('click', openPage);
    });
})(jQuery);